package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.ImpSignInfo;
import com.whnk.pm.service.IImpSignInfoService;

/**
 * 考勤导入 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-11
 */
@Controller
@RequestMapping("/pm/impSignInfo")
public class ImpSignInfoController extends BaseController
{
    private String prefix = "pm/impSignInfo";
	
	@Autowired
	private IImpSignInfoService impSignInfoService;
	
	@RequiresPermissions("pm:impSignInfo:view")
	@GetMapping()
	public String impSignInfo()
	{
	    return prefix + "/impSignInfo";
	}
	
	/**
	 * 查询考勤导入列表
	 */
	@RequiresPermissions("pm:impSignInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ImpSignInfo impSignInfo)
	{
		startPage();
        List<ImpSignInfo> list = impSignInfoService.selectImpSignInfoList(impSignInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增考勤导入
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存考勤导入
	 */
	@RequiresPermissions("pm:impSignInfo:add")
	@Log(title = "考勤导入", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ImpSignInfo impSignInfo)
	{		
		return toAjax(impSignInfoService.insertImpSignInfo(impSignInfo));
	}

	/**
	 * 修改考勤导入
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		ImpSignInfo impSignInfo = impSignInfoService.selectImpSignInfoById(id);
		mmap.put("impSignInfo", impSignInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存考勤导入
	 */
	@RequiresPermissions("pm:impSignInfo:edit")
	@Log(title = "考勤导入", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ImpSignInfo impSignInfo)
	{		
		return toAjax(impSignInfoService.updateImpSignInfo(impSignInfo));
	}
	
	/**
	 * 删除考勤导入
	 */
	@RequiresPermissions("pm:impSignInfo:remove")
	@Log(title = "考勤导入", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(impSignInfoService.deleteImpSignInfoByIds(ids));
	}

	@Log(title = "Excel导入考勤", businessType = BusinessType.UPDATE)
	@PostMapping("/upload")
	@ResponseBody
	public AjaxResult signExcelFileUpload(@RequestParam("signFileUpload") MultipartFile file) throws Exception {
		impSignInfoService.signExcelFileUpload(file);
		return success();
	}
	
	
	@Log(title = "生成项目和成员信息", businessType = BusinessType.OTHER)
	@PostMapping("/addProsAndMemsBySign")
	@ResponseBody
    public AjaxResult addProsAndMemsBySign() {
		impSignInfoService.addProsAndMemsBySign();
		return success();
	}
	
	@Log(title = "生成加班信息", businessType = BusinessType.OTHER)
	@PostMapping("/addWowInfoBySign")
	@ResponseBody
    public AjaxResult addWowInfoBySign() {
		impSignInfoService.addWowInfoBySign();
		return success();
	}
	
	@Log(title = "生成缺勤信息", businessType = BusinessType.OTHER)
	@PostMapping("/addIdleBySign")
	@ResponseBody
    public AjaxResult addIdleBySign() {
		impSignInfoService.addIdleBySign();
		return success();
	}
}
